/**
 * @ClassName LC977
 * @Author ykx
 * @Date 2024/6/30 17:36
 * @Version 1.0
 */
public class LC977 {
    public static void main(String[] args) {

    }

    public int[] sortedSquares(int[] nums) {

        int left = 0;
        int right = nums.length - 1;
        int index = nums.length - 1;
        int[] result = new int[nums.length];

        while (right >= left) {
            if (nums[left] * nums[left] > nums[right] * nums[right]) {
                result[index] = nums[left] * nums[left];
                index--;
                left++;
            } else {
                result[index] = nums[right] * nums[right];
                index--;
                right--;
            }
        }

        return result;
    }

}
